#pragma once
#include<iostream>
#include<pthread.h>
#include<unistd.h>
#include"Mutex.hpp"
namespace MutexMudole{
    class Mutex{
        private:
        pthread_mutex_t mutex;
        public:
        Mutex(){
            pthread_mutex_init(&mutex,NULL);
        }
        ~Mutex(){
            pthread_mutex_destroy(&mutex);
        }
        void Lock(){
            pthread_mutex_lock(&mutex);
        }
        void UnLock(){
            pthread_mutex_unlock(&mutex);
        }
        pthread_mutex_t* getmutex(){
            return &mutex;
        }
    };
    class LockGuard{
        public:
        LockGuard(Mutex& mutex):mutex_(mutex){
            mutex_.Lock();
        }
        ~LockGuard(){
            mutex_.UnLock();
        }
        private:
        Mutex& mutex_;
    };
}